package com.joysuch.wwyt.baidu.util;

import cn.hutool.core.codec.Base64Encoder;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.apache.pdfbox.io.IOUtils;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

public class DzPrtqUtils {

    public static int parseLikeNum(String like) {
        if(like == null || like.length() == 0) {
            return 0;
        }
        return getLikeList(like).size();
    }

    public static List<Long> getLikeList(String like) {
        try {
            List<Long> list = new Gson().fromJson(like, new TypeToken<List<Long>>(){}.getType());
            return list;
        } catch(Exception e) {
        }
        return new ArrayList<>();
    }

    public static String readFileToBase64(InputStream is) throws IOException {
        byte[] bs = IOUtils.toByteArray(is);
        return Base64Encoder.encode(bs);
    }

}
